import { defineStore } from "pinia";

export const workbenchScreenStore = defineStore("workbenchScreen", {
  state: () => {
    return {
      user: localStorage.getItem("info") ? JSON.parse(localStorage.getItem("info")) : {},
      projectId: null,
      gatewayId: null,
      project: {},
      projectList: [],
      menuText: "无线设备管理->设备列表",
      projectText: "->49",
      gatewayText: "->官方展厅M",
    };
  },
  actions: {
    // 设置导航菜单
    setMenuText(str) {
      this.menuText = str;
      this.projectText = "";
      this.gatewayText = "";
    },
    setProjectText(str) {
      this.projectText = "->" + str;
      this.gatewayText = "";
    },
    setGatewayText(str) {
      this.gatewayText = "->" + str;
    },
    // 设置项目信息
    setProject(project) {
      this.project = project;
      this.setProjectId(project.id);
    },
    setProjectList(list) {
      this.projectList = list.sort((a, b) => {
        return b.lightFixtureCount - a.lightFixtureCount;
      });
      this.setProject(list[0] || []);
    },
    setProjectId(id) {
      console.log("setProjectId->", id);
      this.projectId = id;
    },
    setGatewayId(id) {
      this.gatewayId = id;
    },
  },
});
